package com.jjb.www.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.view.View;

import com.baidu.ocr.ui.camera.CameraActivity;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.hjq.shape.view.ShapeButton;
import com.hjq.shape.view.ShapeEditText;
import com.hjq.shape.view.ShapeImageView;
import com.jjb.www.R;
import com.jjb.www.app.AppActivity;
import com.jjb.www.http.api.AgencyListApi;
import com.jjb.www.http.api.RealNameApi;
import com.jjb.www.http.api.UpdateImageApi;
import com.jjb.www.http.glide.GlideApp;
import com.jjb.www.http.model.HttpData;
import com.jjb.www.http.model.HttpList;
import com.jjb.www.utils.FileUtil;

import java.io.File;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2019/04/20
 *    desc   : 去实名认证
 */
public class GoRealNameActivity extends AppActivity {
    private ShapeImageView mImgICard;
    private ShapeEditText mEdtName;
    private ShapeEditText mEdtIdCar;
    private ShapeButton mBtnPut;
    private String idCarImg = "";


    @Override
    protected int getLayoutId() {
        return R.layout.activity_go_real_name;
    }

    @Override
    protected void initView() {
        mImgICard = findViewById(R.id.img_i_card);
        mEdtName = findViewById(R.id.edt_name);
        mEdtIdCar = findViewById(R.id.edt_id_car);
        mBtnPut = findViewById(R.id.btn_put);
        setOnClickListener(mImgICard,mBtnPut);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View view) {
        if (view==mImgICard){
            Intent intent = new Intent(getContext(), CameraActivity.class);
            intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH,
                    FileUtil.getSaveFile(getApplication()).getAbsolutePath());
            intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_FRONT);
//            startActivityForResult(intent, REQUEST_CODE_CAMERA);
            startActivityForResult(intent, (resultCode, data) -> {
                if (resultCode== Activity.RESULT_OK){
                    String contentType = data.getStringExtra(CameraActivity.KEY_CONTENT_TYPE);
                    String filePath = FileUtil.getSaveFile(getContext()).getAbsolutePath();
                    Log.e("startActivityForResult",contentType+"---"+filePath);
                }

            });
        }else if (view==mBtnPut){
            if (idCarImg.equals("")){
                toast("请上传身份证照片");
                return;
            }
            if (mEdtName.getText().toString().equals("")){
                toast("请填写您的真实姓名");
                return;
            }
            if (mEdtIdCar.getText().toString().equals("")){
                toast("请填写您的身份证号码");
                return;
            }
            EasyHttp.post(this)
                    .api(new RealNameApi()
                    .setReal_name(mEdtName.getText().toString())
                    .setId_card(mEdtIdCar.getText().toString())
                    .setId_card_img(idCarImg))
                    .request(new HttpCallback<HttpData<Void>>(this) {

                        @Override
                        public void onSucceed(HttpData<Void> data) {

                        }
                    });
        }
    }

    private void updateImage(File file) {
        EasyHttp.post(this)
                .api(new UpdateImageApi()
                        .setFile(file))
                .request(new HttpCallback<HttpData<UpdateImageApi.Bean>>(this) {

                    @Override
                    public void onSucceed(HttpData<UpdateImageApi.Bean> data) {

                    }
                });
    }
}